define(["app","js/risk/typeView","js/init", 'js/utils','js/util/socketUtil','js/risk/riskModel'], 
	function(app, diagView,base,Utils,initSocket,model) {
	
	//初始化标志
	var initialized = false;
	var module = "risk";
	var bindings = [		
		//导航链接
		{
			element: '.risk-type-grid .risk-type-link',
			event: 'click',
			handler: clickType
		}
		,
		
		//导航链接
		{
			element: '.risk-type-page .back-link',
			event: 'click',
			handler: clickBack
		}
		
	];
	
	function clickType(e){
		
		
		if(!app.mainView){
			app = app.getApp();
		}		
		
		var typeCode ,typeName
		if(e && e.currentTarget){
			typeCode = $(e.currentTarget).attr('pid')
			typeName = $(e.currentTarget).attr('pname')
			
			model.setCC({bizcode:typeCode,bizName:typeName})
		}
		
		if(typeCode){
			var c = model.getCC();
			require(['js/risk/controller/'+ c.bizcode + 'Controller'], function(controller) {
				controller.getPie();
			});
		}
	}
	
	
	/**
	 * 回退按钮事件
	 */
	function clickBack(){
		if(!app.mainView){
			app = app.getApp();
		}
		
		var _cv = app.f7.getCurrentView();

		if(_cv && _cv.router){
			
			_cv.router.load({pageName:'risk/main'});
		}
	}

	function init(query){
		
		if(!query || query.length<=0){
			return 
		}
		if(!app.mainView){
			app = app.getApp();
		}
		
		if(query.name){
			$('.risk-type-page .biz-title').html(query.name)
		}
		if(query.code){
			if(model.risk){
				//显示分类命名
				var rows =[]
				$.each(model.risk,function(i,o){
					if(o.type){
						
						$.each(o.type,function(ti,to){
							
							if(to == query.code){
								
								var d = {code:o.code,name:o.name,type:to};
								rows.push(d);
							}
						})
					}
				})	
				
				diagView.render({
					model	: rows,
					bindings: bindings
				});				
			}
		}		
		app.f7.hidePreloader('loading...');		
	}	

	return {
		init: init
	};
});